//
//  STLogsListTableCell.swift
//  SlowTrajectory
//
//  Created by iOS-Czz on 2023/10/23.
//

import UIKit

class STLogsListTableCell: UITableViewCell {
    @IBOutlet var bgView: UIView!
    @IBOutlet var dayLabel: UILabel!
    
    @IBOutlet var ideaIcon: UIImageView!
    @IBOutlet var otherDayLabel: UILabel!
    @IBOutlet var logLabel: UILabel!
    @IBOutlet var dateLabel: UILabel!
    @IBOutlet var pic: UIImageView!
   
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    override func layoutIfNeeded() {
        super.layoutIfNeeded()
        self.bgView.addDashedBorder(color: .black, lineWidth: 1, cornerRadius: 15)
        self.dayLabel.addDashedBorder(color: .black, lineWidth: 1, cornerRadius: 15)
        self.pic.addDashedBorder(color: .black, lineWidth: 1, cornerRadius: 20)
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }

    var model: STLogsModel? {
        didSet {
            self.pic.image = UIImage.loadImage((model?.picture)!)
            self.dateLabel.text = model!.day + " " + model!.weekday
            if Date.isDateToday(model!.day, format: "yyyy-MM-dd"){
                self.dayLabel.text = "今天"
                self.dayLabel.isHidden = false
                self.otherDayLabel.isHidden = true
            }else{
                self.dayLabel.isHidden = true
                self.otherDayLabel.isHidden = false
                self.otherDayLabel.text = model?.day.daysAgoString()
            }
            self.ideaIcon.isHidden = model!.idea.isEmpty
            self.logLabel.text = model?.log
        }
    }
    
}
